/**
 * @copyright SilverBiology, LLC
 * @website http://www.silverbiology.com
*/

Ext.namespace('Gbif.Glossary')

Gbif.Glossary.Manager = function(config){
	
	this.termstree = new Gbif.Glossary.TermsTreePanel({
			region: 'west'	
		,	split: true
		,	width: 280
		,	minWidth: 250
		,	collapsible: true
		,	margins: '0 0 5 5'
		,	cmargins: '0 0 0 0'
		,	rootVisible: false
		,	lines: false
		,	autoScroll: true
		,	animCollapse: false
		,	animate: false
		,	collapseMode: 'mini'			
	});
			
	this.tabpanel = new Gbif.Glossary.TabPanel({
			region: 'center'
		,	margins: '0 5 5 0'				
	})

	this.termstree.on('nodeClicked',function(node){
		
		switch (node.attributes.type) {
			case 'doc':
				GBif.Stats.log( 'Contents/' + node.attributes.text );			
				this.tabpanel.stmInfoPanel(node.attributes.text);
				break;
			case 'term':
				GBif.Stats.log( 'Term/' + node.attributes.text );
				if (node.attributes.termStatus != 'Primary') {
					this.invokeTermsTab(node.parentNode.attributes.type, 'Term', Ext.util.Format.substr(node.attributes.parentName,0,1).toUpperCase(), 'iconText', node.attributes.parentName);
				} else {
					this.invokeTermsTab(node.parentNode.attributes.type, 'Term', node.parentNode.attributes.text, 'iconText', node.attributes.text);
				}
				break;
			case 'termType':
			case 'codeStatus':
			case 'code':
				GBif.Stats.log( node.parentNode.attributes.type + '/' + node.attributes.text );
				this.invokeTermsTab(node.parentNode.attributes.type, node.parentNode.attributes.text, node.attributes.text,'iconText');
				break;
		}
		
	},this);

	this.termstree.on('aboutSoftware', function(node){
		this.tabpanel.addTab('About Software', 'docs/about.php', 'iconAbout');
	}, this);
	
	Ext.apply(this, config, {
			autoScroll: true
		,	layout: 'border'
		,	items: [ this.termstree, this.tabpanel ]
	});

	Gbif.Glossary.Manager.superclass.constructor.call(this,config)

}

Ext.extend( Gbif.Glossary.Manager, Ext.Panel, {

	invokeTermsTab: function( type, title, value, icon, id ){
		this.tabpanel.addTermsTab( type, title, value, icon, id );		
	}

});